// 1. 导入 Vue 和 Vuex
import Vue from 'vue'
import Vuex from 'vuex'
import login from '@/store/login.js'
// 2. 将 Vuex 安装为 Vue 的插件
Vue.use(Vuex)

// 3. 创建 Store 的实例对象
const store = new Vuex.Store({
  // TODO：挂载 store 模块
  state: {
    historyRecords: uni.getStorageSync('historysearch') || [],
    keyValue: uni.getStorageSync('keyValue') || '',
    VideoId: uni.getStorageSync('VideoId') || '',
  },
  getters: {},
  mutations: {
    UpdateSearchRecord(state, historysearch) {
      state.historyRecords = historysearch
      this.commit('saveSearchRecord')
    },
    saveSearchRecord(state) {
      uni.setStorageSync('historysearch', state.historyRecords)
    },
    UpdatekeyValue(state, keyValue) {
      state.keyValue = keyValue
      this.commit('savekeyValue')
    },
    savekeyValue(state) {
      uni.setStorageSync('keyValue', state.keyValue)
    },
    UpdateVideoId(state, VideoId) {
      state.VideoId = VideoId
      this.commit('saveVideoId')
    },
    saveVideoId(state) {
      uni.setStorageSync('VideoId', state.VideoId)
    }
  },
  modules: {
    login
  }
})

// 4. 向外共享 Store 的实例对象
export default store
